package com.lhl.biz.template.server.service;

import com.lhl.biz.template.api.server.service.TemplateService;
import com.lhl.biz.template.api.shared.domain.dto.TempDTO;
import com.lhl.biz.template.api.shared.domain.dto.TemplateDTO;
import com.lhl.biz.template.api.shared.domain.vo.TemplateVO;
import com.lhl.biz.template.server.manager.TemplateManager;
import com.lhl.biz.template.server.mapstruct.TemplateDtoMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.time.LocalDate;
import java.util.List;

/**
 * @className: TemplateServiceImpl
 * @description: 实现类
 * @author: king
 * @date: 2020-06-17 13:26
 **/
@Service
@Slf4j
@Validated
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TemplateServiceImpl implements TemplateService {
    private final TemplateManager templateManager;
    private final TemplateDtoMapper templateDtoMapper;

    @Override
    public TemplateDTO queryById(String id) {
        return templateManager.queryById(id).orElse(null);
    }

    @Override
    public List<TemplateDTO> queryByJson(String code) {
        return templateManager.queryByJson(code).orElse(null);
    }

    @Override
    public List<TemplateDTO> queryByName(String name) {
        return templateManager.queryByName(name).orElse(null);
    }

    @Override
    public List<TemplateDTO> findByBirthdayIsGreaterThanEqual(LocalDate birthday) {
        return templateManager.findByBirthdayIsGreaterThanEqual(birthday).orElse(null);
    }

    @Override
    public TempDTO findByName(String name) {
        log.debug("执行SQL");
        return templateManager.findByName(name).orElse(null);
    }

    @Override
    public void save(TemplateVO templateVO) {
        templateManager.save(templateVO);
    }

    @Override
    public TemplateDTO findById(String id) {
        return templateManager.findById(id).orElse(null);
    }
}
